#pragma once
#include <list>
#include "vector.h"
#include "plane.h"
#include "boundingsphere.h"
#include "boundingbox.h"

/**
 * Klasa trojkata 3D
 *
 * @author Krzysztof Klein
 * @version 0.1
 */
class Triangle
{

	/**
	 * Wierzcholki
	 */
	Vector vertices[3];

	/**
	 * Plaszczyzna trojkata
	 */
	Plane plane;

	/**
	 * Sfera otaczajaca
	 */
	BoundingSphere boundingSphere;

	/**
	 * Prostopadloscian otaczajacy
	 */
	BoundingBox boundingBox;

public:

	/**
	 * Konstruktor domyslny
	 */
	Triangle() { }


	/**
	 * Konstruktor z 3 punktow
	 */
	Triangle(const Vector &v1, const Vector &v2, const Vector &v3)
	{
		vertices[0] = v1;
		vertices[1] = v2;
		vertices[2] = v3;
	}


	/**
	 * Zwraca wierzcholki trojkata
	 *
	 * @return Wierzcholki trojkata
	 */
	Vector* getVertices() { return vertices; }

	/**
	 * Zwraca wierzcholki trojkata
	 *
	 * @return Wierzcholki trojkata
	 */
	const Vector* getVertices() const { return vertices; }


	/**
	 * Plaszczyzna trojkata
	 *
	 * @return Plaszczyzna trojkata
	 */
	Plane& getPlane() { return plane; }

	/**
	 * Plaszczyzna trojkata
	 *
	 * @return Plaszczyzna trojkata
	 */
	const Plane& getPlane() const { return plane; }

	/**
	 * Sfera otaczajaca
	 *
	 * @return Sfera otaczajaca
	 */
	BoundingSphere& getBoundingSphere() { return boundingSphere; }

	/**
	 * Sfera otaczajaca
	 *
	 * @return Sfera otaczajaca
	 */
	const BoundingSphere& getBoundingSphere() const { return boundingSphere; }

	/**
	 * Prostopadloscian otaczajacy
	 *
	 * @return Prostopadloscian otaczajacy
	 */
	BoundingBox& getBoundingBox() { return boundingBox; }

	/**
	 * Prostopadloscian otaczajacy
	 *
	 * @return Prostopadloscian otaczajacy
	 */
	const BoundingBox& getBoundingBox() const { return boundingBox; }


	/**
	 * Oblicza plaszczyzne trojkata
	 */
	void recalculatePlane()
	{
		plane = Plane(vertices[0], vertices[1], vertices[2]);
	}


	/**
	 * Oblicza sfere otaczajaca
	 */
	void recalculateBoundingSphere()
	{
		boundingSphere = BoundingSphere(vertices);
	}


	/**
	 * Oblicza prostopadloscian otaczajacy
	 */
	void recalculateBoundingBox()
	{
		boundingBox = BoundingBox(vertices);
	}

};
